import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
 * Author: Sergey Saiyan
 * Created: 19.07.13 23:24 
 */
class StartTomcat extends DefaultTask {

    def tomcatRootDir = project.tomcatDir

    StartTomcat() {
        setDescription('Starts local Tomcat')
        setGroup('Development server')
    }

    @TaskAction
    def deploy() {
        def binDir = "${tomcatRootDir}/bin"
        project.logger.info ">>> starting $tomcatRootDir"
        ant.exec(osfamily: 'windows', dir: "${binDir}", executable: 'cmd.exe', spawn: true) {
            env(key: 'NOPAUSE', value: true)
            arg(line: '/c start callAndExit.bat debug.bat')
        }
        ant.exec(osfamily: 'unix', dir: "${binDir}", executable: '/bin/sh') {
            arg(line: 'debug.sh')
        }
    }


}
